//
//  ButtonExtension.swift
//  loveHHEveryDay
//
//  Created by yw on 2025/4/2.
//

import Foundation
import SwiftUI

struct MainTextModifier:ViewModifier {
    var fontSize:CGFloat = 16
    var fontWeight:Font.Weight = .medium
    var foreColor:Color = Color("color_text_black")
    func body(content: Content) -> some View {
        content
            .font(Font.system(size: fontSize, weight:fontWeight, design: .rounded))
            .foregroundColor(foreColor)
    }
}

struct MainButtonModifier:ViewModifier {
    @AppStorage("curren_main_color") var currentMainColor = "color_main_01"
//    var backColor:Color = Color(currentMainColor)
    var fontSize:CGFloat = 16
    var fontWeight:Font.Weight = .medium
    var width:CGFloat = .infinity
    
    func body(content: Content) -> some View {
        content.font(Font.system(size: fontSize, weight:fontWeight, design: .rounded))
            .foregroundColor(Color("color_bg"))
            .frame(width: width, height: 56)
            .background(Color(currentMainColor))
            .cornerRadius(28)
        
    }
}


struct ShakeButton<V>:View where V:View {
    let label:V
    let action:() ->Void
    var btnW:CGFloat = 200
    var btnH:CGFloat = 54
    var textColor:Color = .white
    var fontSize:CGFloat = 16
    var fontWeight:Font.Weight = .regular
    var fontDesign:Font.Design = .rounded
    init(label: V,
         btnW:CGFloat = 200,
         btnH:CGFloat = 54,
         textColor:Color = .white,
         fontSize:CGFloat = 16,
         fontWeight:Font.Weight = .regular,
         fontDesing:Font.Design = .rounded,
         action: @escaping () -> Void) {
        self.label = label
        self.action = action
        self.btnW = btnW
        self.btnH = btnH
        self.textColor = textColor
        self.fontSize = fontSize
        self.fontWeight = fontWeight
        self.fontDesign = fontDesing
    }
    
    var body: some View {
        Button(action: {
//            let generator = UINotificationFeedbackGenerator()
//            generator.prepare()
//            generator.notificationOccurred(.warning)
//            AudioServicesPlaySystemSound(1520)
            let generator = UIImpactFeedbackGenerator(style: .light)
            generator.prepare()
            generator.impactOccurred()
            UIApplication.shared.endEditing()
            action()
        }, label: {
            label.frame(maxWidth: .infinity)
                .font(Font.system(size: self.fontSize, weight: self.fontWeight, design: self.fontDesign))
        }) .frame(width: btnW,height: btnH)
            .background(LinearGradient(colors: [Color("color_pink_01"),Color("color_pink_02")], startPoint: .leading, endPoint: .trailing))
            .foregroundColor(textColor)
            .cornerRadius(27)
            
            
    }
}
